Student Solution

-->

"Education is the most powerful weapon which you can use to change the world”
– Nelson Mandela

1 University

1 Course

1 Subject

Week 4 Lab

Week 4 Lab

Q WILMINGTON UNIVERSITY COLLEGE OF TECHNOLOGY SEC 230 - Introduction to Linux OBJECTIVES: In this lab you find the 10 most frequently used words in a text file. To accomplish this task, you will chain commands together in a series of pipe operations. The lab will guide you through the commands that must be run. INSTRUCTIONS: Carefully follow the instructions on each page. You will submit several screenshots. Search for INSERT or SCREENSHOT in uppercase to find out the exact pages. There are questions to answer. Search for QUESTION in uppercase to find out the exact pages. PREREQUISITES: • "How to use the Snipping Tool on Windows 10" video at https://www.youtube.com/watch?v=ayi5-7QPNcA • "How to Take a Screenshot on a Mac" video at https://www.youtube.com/watch?v=h3RkDPfphSQ • How to access SEC 230 vApp.docx COMMENTS: I do NOT want a screenshot of your entire VM desktop window when only a portion is needed to demonstrate that you have followed the instructions. For examples, see the screenshots in this document. Ensure that you complete the entire lab. You will know when you see "THIS IS THE LAST PAGE OF THE LAB". ? • Login to the CentOSVM VM. Password is "student" • Start a Terminal window • The following are preparation steps for this lab • Run 'su' to become the root user. Password is "Careful!" • Run 'yum install –y dos2unix' to install this utility • Run 'exit' to become user labuser again • Run 'clear' • Run 'cd' to go to the home directory • Run 'id' to verify that you are user labuser • Run 'which dos2unix' to verify that the command was installed • Run 'wget http://textfiles.com/etext/REFERENCE/all11.txt 2> /dev/null' to get a text file. NOTE: There are two lowercase "el" and the number eleven • Run ‘ls –l all11.txt’. WARNING: all11.txt should be shown. If you see an erorr instead, then you mistyped the wget command • Run 'head –n 165 all11.txt > usdeclar.txt' to extract the Declaration of Indepence. • Run 'file usdeclar.txt' to show it is a DOS text file; i.e. it has CRLF line terminations • Run 'dos2unix usdeclar.txt' to convert usdeclar.txt from DOS to Unix text format. This is needed for later steps to work properly • Run 'file usdeclar.txt' to show it is a Unix text file • Run 'wc usdeclar.txt' to verify that the file was properly converted to Unix text format. NOTE: If you do not get the same wc results as shown, repeat all steps • Run 'date' ? • Using Snipping Tool, take a screenshot. It should look like ? INSERT YOUR SCREENSHOT HERE. IT IS WORTH 10 POINTSStep 1 Use 'sed' to remove all punctuation from usdeclar.txt, which would be a comma, colon, semicolon, dash, ampersand and period. You must also convert double spaces to a single space. See slide "Useful sed expressions" in Unit 8 for hints . NOTE: There are ways to remove multiple characters, but do not do so. HINT: In each step below, replace <exprXX> with the appropriate sed expression. Remember to enclose the sed expression with single quotes Step 1a – remove commas • Run echo "a, b, c" > commas.txt to create a test file • Run sed '<expr1a>' commas.txt to verify that your expression removes the commas Step 1b – remove colons • Run echo "a: b: c" > colons.txt to create a test file • Run sed '<expr1b>' colons.txt to verify that your expression removes the colons Step 1c – remove semicolons • Run echo "a; b; c" > semicolons.txt to create a test file • Run sed '<exp1c>' semicolons.txt to verify that your expression removes the semicolons Step 1d – remove dashes • Run echo "a- b- c" > dashes.txt to create a test file • Run sed '<expr1d>' dashes.txt to verify that your expression removes the dashes Step 1e – remove ampersands • Run echo "a& b& c" > ampersands.txt to create a test file • Run sed '<expr1e>' ampersands.txt to verify that your expression removes the ampersands Step 1f – remove periods • Run echo "a. b. c" > periods.txt to create a test file • Run sed '<expr1f>' periods.txt to verify that your expression removes the periods • CAUTION: The period must be escaped, or it will be treated as a wildcard character, which is not what you want Step 1g – convert double spaces to single spaces • usdeclar.txt contains double spaces. To simplify Step 2, we need to convert double spaces to a single space • Run echo "a b c" > spaces.txt to create a test file. NOTE: There are two spaces after a and two spaces after b • Run sed '<expr1g>' spaces.txt to verify that your expression converts double spaces to single spaces HINT: What would be the sed expression to replace a double aa with a single a or a double bb with a single b? Then just remember that a space is just another character like a or b. Step 1h – remove blank lines • Run echo "a b c" > lines.txt to create a test file with non-blank line • Run echo "" >> lines.txt to add blank line to test file. NOTE: There is no space between the pair of double quotes • Run echo "" >> lines.txt to add blank line to test file • Run echo "d e f" >> lines.txt.to add non-blank line to test file • Run sed '<expr1h>' lines.txt to verify that your expression removes blank lines Step 1j – chain the commands • Chain all of these 'sed' commands together using the pipe operation and rediect the output to sed_edits.txt • The command chain should look like sed '<expr1a>' usdeclar.txt | sed '<expr1b>' | sed '<expr1c>' | sed '<expr1d>' | sed '<expr1e>' | sed '<expr1f>' | sed '<expr1g>' | sed 'expr1h' > sed_edits.txt NOTE: The 'sed' order be for removing commas, colons, semicolons, dashes, ampersands, periods and blank lines, and then converting double spaces to single spaces. WARNING: There is only one space before and after the pipe operator (vertical bar) The greater than sign before sed_edits.txt saves the results of the command chain to this file, which will be used in Step 2. ? This QUESTION is worth 20 points. Write your answer in the box. What is the command chain you will run? WARNING: The only instance of usdeclar.txt should be before the first pipe character. Do NOT have more than one instance of usdeclar.txt. Look carefully at the command chain in Step 1j sed 's/,//g' | sed 's/://g' | sed 's/;//g' | sed 's/-//g' | sed 's/&//g' | sed 's/\.//g' | sed '/^$/d'> sed_edits.txt ? • Run 'clear' • Run the command chain you entered in the box • Run 'head sed_edits.txt' • Run 'wc sed_edits.txt' to get the line, word and byte count of sed_edits.txt • Run 'grep '[,:;-&]' sed_edits.txt | grep ' ' | grep '\.' | grep '^$' WARNING: There is only one space before and after the pipe operator (vertical bar) NOTE: The expressions of the grep commands are <bracket><comma><colon><semicolon><dash><ampersand><bracket> <space><space> <backslash><dot> <carat><dollar-sign> • Run 'date' • Using Snipping Tool, take a screenshot. DO NOT PROCEED IF YOUR SCREENSHOT DOES NOT MATCH (except for the difference in the 'date' command output ) ? INSERT YOUR SCREENSHOT HERE. IT IS WORTH 10 POINTS

View Related Questions

Solution Preview

This solution is in image format.